package com.bolt.report.config;

import com.bolt.core.view.freemarker.BoltTags;
import com.bolt.report.engine.pool.DruidJdbcPoolImpl;
import com.bolt.report.engine.pool.JdbcConnectionPool;
import com.bolt.report.engine.query.QueryExecuteFactory;
import freemarker.template.Configuration;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;

@Configurable
public class BRReportAutoConfig {

    @Bean("reportFreeMarkerConfig")
    public Configuration getConfiguration() throws TemplateModelException {
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
        // 设置FreeMarker的模版文件位置
        cfg.setClassForTemplateLoading(BRReportAutoConfig.class, "/");
        cfg.setNumberFormat("###############");
        cfg.setBooleanFormat("true,false");
        cfg.setDefaultEncoding("UTF-8");
        cfg.setSharedVariable("bolt", new BoltTags());
        return cfg;
    }

    @Bean("druidJdbcPool")
    public JdbcConnectionPool newJdbcConnectionPool() {
        JdbcConnectionPool jdbcConnectionPool = new DruidJdbcPoolImpl(null);
        return jdbcConnectionPool;
    }

    @Bean
    public QueryExecuteFactory queryExecuterFactory(JdbcConnectionPool jdbcConnectionPool) {
        return new QueryExecuteFactory(jdbcConnectionPool);
    }





}